import axios from "axios";
import {Message} from "element-ui";

const request = axios.create({
    baseURL: "/api", // url = base url + request url
    withCredentials: true, // send cookies when cross-domain requests
    timeout: 5000 // request timeout
})
request.interceptors.response.use(
    response => {
        const token = response.headers['token'];
        if (token !== undefined)
            localStorage.setItem('token', token)
        return response.data
    },
    error => {

        console.log(error)// for debug

        return Promise.reject(error)

    }
);
request.interceptors.request.use(config => {
    config.headers = {"Token": localStorage.getItem('token')}
    return config;
},);


export default request;
